/*picBase是base64图片带头部的完整编码*/
var ba64=function(pic, token, fun){
	//接受完整的base64   后台给得token   
	var d = pic.split(",");
	var pic = d[1];
	var base = new Base64();
	//这里是自定义存的图片名字，防止名字 相同   用乱码
	var key=base.encode("user_pic/"+Date.parse(new Date())+uuid());	
	var url = "http://upload-z2.qiniu.com/putb64/-1/key/"+key; //非华东空间需要根据注意事项 1 修改上传域名
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function() { 
		if(xhr.readyState == 4 && xhr.status == 200) {
			var json = JSON.parse(xhr.responseText);
			fun(json);
		}
	}
	xhr.open("POST", url, true);
	xhr.setRequestHeader("Content-Type", "application/octet-stream");
	xhr.setRequestHeader("Authorization", "UpToken " + token);
	xhr.send(pic);
}
var uuid=function() {
    let s = [];
    let hexDigits = "0123456789abcdef";
    for (let i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
    s[8] = s[13] = s[18] = s[23] = "-";
    return s.join("");
};